package com.houweishi.module.fileUploadRecord.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.fileUploadRecord.domain.BizFileUploadRecord;
import com.houweishi.module.fileUploadRecord.service.IBizFileUploadRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件上传记录Controller
 * 
 * @author houweishi
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/module/fileUploadRecord")
public class BizFileUploadRecordController extends BaseController
{
    @Autowired
    private IBizFileUploadRecordService bizFileUploadRecordService;

    /**
     * 查询文件上传记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizFileUploadRecord bizFileUploadRecord)
    {
        // startPage();
        List<BizFileUploadRecord> list = bizFileUploadRecordService.selectBizFileUploadRecordList(bizFileUploadRecord);
        return getDataTable(list);
    }

    /**
     * 导出文件上传记录列表
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:export')")
    @Log(title = "文件上传记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizFileUploadRecord bizFileUploadRecord)
    {
        List<BizFileUploadRecord> list = bizFileUploadRecordService.selectBizFileUploadRecordList(bizFileUploadRecord);
        ExcelUtil<BizFileUploadRecord> util = new ExcelUtil<BizFileUploadRecord>(BizFileUploadRecord.class);
        util.exportExcel(response, list, "文件上传记录数据");
    }

    /**
     * 获取文件上传记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizFileUploadRecordService.selectBizFileUploadRecordById(id));
    }

    /**
     * 新增文件上传记录
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:add')")
    @Log(title = "文件上传记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizFileUploadRecord bizFileUploadRecord)
    {
        try {
            return bizFileUploadRecordService.insertBizFileUploadRecord(bizFileUploadRecord);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    /**
     * 修改文件上传记录
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:edit')")
    @Log(title = "文件上传记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(BizFileUploadRecord bizFileUploadRecord)
    {
        try {
            return bizFileUploadRecordService.updateBizFileUploadRecord(bizFileUploadRecord);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    /**
     * 删除文件上传记录
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:remove')")
    @Log(title = "文件上传记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizFileUploadRecordService.deleteBizFileUploadRecordByIds(ids));
    }

    /**
     * 文件下载
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:download')")
    @Log(title = "文件下载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/downloadFile")
    public AjaxResult downloadFile(@RequestBody BizFileUploadRecord bizFileUploadRecord,HttpServletResponse response)
    {
        try {
            return bizFileUploadRecordService.downloadFile(bizFileUploadRecord,response);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    /**
     * 文件上传
     */
    @PreAuthorize("@ss.hasPermi('module:fileUploadRecord:upload')")
    @Log(title = "文件上传", businessType = BusinessType.EXPORT)
    @PostMapping("/uploadFile")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file)
    {
        try {
            return bizFileUploadRecordService.uploadFile(file);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }


}
